/* 
 * File:   Utilities.h
 * Author: RedEyedKiller
 *
 * Created on 14 Ιούλιος 2010, 3:29 μμ
 */

#ifndef UTILITIES_H
#define	UTILITIES_H

#include <vector>
#include <list>
#include <map>
#include <string>

/**
 * Calls delete for every element of the list.
 * @param lista - The list to clear out.
 * @param T - The type of elements of list.
 */
template<typename T>
void SafeRelease(std::list<T>& lista)
{
    using namespace std;
    typename list<T>::iterator iter;
    for (iter = lista.begin(); iter != lista.end(); ++iter)
    {
        T toDie = (*iter);
        delete toDie;
    }
    lista.clear();
}

/**
 * Calls delete for every element of the vector.
 * @param vect - The vector to clear out.
 * @param T - The type of elements of vector.
 */
template<typename T>
void SafeRelease(std::vector<T>& vect)
{
    using namespace std;
    typename std::vector<T>::iterator iter;
    for (iter = vect.begin(); iter != vect.end(); ++iter)
    {
        T toDie = (*iter);
        delete toDie;
    }
    vect.clear();
}

/**
 * Calls delete for every element of the map.
 * @param map - The map to clear out.
 * @param T - The type of elements of map.
 */
template<typename Key,typename T>
void SafeRelease(std::map<Key,T>& map)
{
    using namespace std;
    typename std::map<Key,T>::iterator iter;
    for (iter = map.begin(); iter != map.end(); ++iter)
    {
        T toDie = iter->second;
        delete toDie;
    }
    map.clear();
}



/**
 * Template functor that deallocates an object of any type.
 *
 * @param ptr - pointer to the object.
 */

template <class PtrType>
struct FreePointer
{
    void operator()(PtrType *ptr)
    {
        delete ptr;
    }
};


/**
 * Coverts a string to uppercase.
 * 
 * @param str: OUTPUT parameter, modifies this string's characters.
 */ 

void StrToUpper(std::string& str);

#endif	/* UTILITIES_H */

